package java07;
import java.io.*;
public class InputSteramReaderTest01 {
    public static void main(String[] args){
        FileInputStream in = null;
        FileOutputStream out = null;
        InputStreamReader isr = null;
        OutputStreamWriter osw = null;
        BufferedReader br = null;
        BufferedWriter bw = null;
        try {
            //创建字节输入流对象，获取源文件
            in = new FileInputStream("D:\\JAVA\\source\\reader.txt");
            //将字节流输入对象抓换成字符输入流对象
            isr = new InputStreamReader(in);
            //创建字符输入缓冲流对象
            br = new BufferedReader(isr);
            //创建字节输出流对象。指定目标文件
            out = new FileOutputStream("D:\\JAVA\\target\\writer.txt");
            //将字节输出流对象转换成字符输出流对象
            osw = new OutputStreamWriter(out);
            //创建字符输出缓冲流对象
            bw = new BufferedWriter(osw);
            //定义一个字符串变量
            String line = null;
            //通过循环判断是否读到文件末尾
            while((line = br.readLine()) != null){
                //输出读到的文件
                bw.write(line);
                bw.newLine();
                bw.flush();
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //关闭流
            if(br != null){
                try {
                    br.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if(bw != null){
                try {
                    bw.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }
}
